package cn.edu.hunau.java.week03.day02;

import com.sun.net.httpserver.Filter;
import com.sun.net.httpserver.HttpExchange;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AppleTest {
    @Test
    public void testByColor(){
        List<Apple> datas=getApplies();
        List<Apple> redApples=FilterApple.filterByColor(datas,"红色");
        List<Apple> greenApples=FilterApple.filterByColor(datas,"绿色");
        System.out.println(redApples);
        System.out.println(greenApples.size());
    }

    @Test
    public void testByType(){
        List<Apple> datas=getApplies();
        List<Apple> Apple01=FilterApple.filterByType(datas,"红富士");
        System.out.println(Apple01);
    }

    @Test
    public void testByWeight(){
        List<Apple> datas=getApplies();
        List<Apple> result=FilterApple.filterByWeight(datas, Double.parseDouble("130.0"));
        System.out.println(result);
    }

    @Test
    public void testFilter(){
        List<Apple> datas=getApplies();;
        List<Apple> result= FilterApple.filter(datas,new Filter(){
            @Override
            public void doFilter(HttpExchange exchange, Chain chain) throws IOException {

            }

            @Override
            public String description() {
                return "";
            }

            public boolean filter(Apple apple) {
            return "红色".equals(apple.getColor()) && apple.getWeight()>130;
            }
        });
        System.out.println(result);
        }


    public List<Apple> getApplies(){
        List<Apple> appleList=new ArrayList<>();
        // 添加50个Apple对象
        appleList.add(new Apple("红富士", "红色", 112.7));
        appleList.add(new Apple("红富士", "红色", 98.5));
        appleList.add(new Apple("红富士", "红色", 156.3));
        appleList.add(new Apple("红富士", "红色", 189.1));
        appleList.add(new Apple("红富士", "红色", 132.4));
        appleList.add(new Apple("红富士", "绿色", 105.6));
        appleList.add(new Apple("红富士", "绿色", 176.2));
        appleList.add(new Apple("红富士", "绿色", 89.3));
        appleList.add(new Apple("红富士", "绿色", 145.8));
        appleList.add(new Apple("红富士", "青色", 167.9));
        appleList.add(new Apple("红富士", "青色", 122.5));
        appleList.add(new Apple("红富士", "青色", 93.7));
        appleList.add(new Apple("红富士", "青色", 192.3));
        appleList.add(new Apple("瑞雪", "红色", 101.2));
        appleList.add(new Apple("瑞雪", "红色", 155.8));
        appleList.add(new Apple("瑞雪", "红色", 138.4));
        appleList.add(new Apple("瑞雪", "红色", 85.6));
        appleList.add(new Apple("瑞雪", "绿色", 177.3));
        appleList.add(new Apple("瑞雪", "绿色", 112.9));
        appleList.add(new Apple("瑞雪", "绿色", 143.2));
        appleList.add(new Apple("瑞雪", "绿色", 97.8));
        appleList.add(new Apple("瑞雪", "青色", 188.5));
        appleList.add(new Apple("瑞雪", "青色", 126.4));
        appleList.add(new Apple("瑞雪", "青色", 109.1));
        appleList.add(new Apple("瑞雪", "青色", 163.7));
        appleList.add(new Apple("红星", "红色", 92.4));
        appleList.add(new Apple("红星", "红色", 151.6));
        appleList.add(new Apple("红星", "红色", 128.3));
        appleList.add(new Apple("红星", "红色", 179.8));
        appleList.add(new Apple("红星", "绿色", 103.5));
        appleList.add(new Apple("红星", "绿色", 147.2));
        appleList.add(new Apple("红星", "绿色", 88.7));
        appleList.add(new Apple("红星", "绿色", 166.9));
        appleList.add(new Apple("红星", "青色", 133.1));
        appleList.add(new Apple("红星", "青色", 115.4));
        appleList.add(new Apple("红星", "青色", 191.2));
        appleList.add(new Apple("红星", "青色", 99.6));
        appleList.add(new Apple("国光", "红色", 108.3));
        appleList.add(new Apple("国光", "红色", 159.7));
        appleList.add(new Apple("国光", "红色", 136.2));
        appleList.add(new Apple("国光", "红色", 87.5));
        appleList.add(new Apple("国光", "绿色", 172.4));
        appleList.add(new Apple("国光", "绿色", 121.8));
        appleList.add(new Apple("国光", "绿色", 149.3));
        appleList.add(new Apple("国光", "绿色", 95.9));
        appleList.add(new Apple("国光", "青色", 183.6));
        appleList.add(new Apple("国光", "青色", 118.7));
        appleList.add(new Apple("国光", "青色", 164.2));
        appleList.add(new Apple("国光", "青色", 104.5));

        return appleList;
    }
}
